﻿<html xmlns:th="http://www.thymeleaf.org">
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>编辑推送组</title>
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <div th:include="layout/resources :: resources"></div>
</head>
<body>
<div class="container-fluid">
    <div id="toolbar">
    </div>
    <table id="table"></table>
    <div class="row text-center">
        <button class="btn btn-default" onclick="save();">保存</button>
    </div>
</div>

</body>
<script th:inline="javascript">
    $(function () {
        $('#table').on('load-success.bs.table', function () {
            $.ajax({
                method: "get",
                url: createUrl("/versionGroup/get/[[${id}]]"),
                success: function (result) {
                    var ids = [];
                    for (i in result) {
                        ids.push(result[i].groupInfoId);
                    }
                    $("#table").bootstrapTable("checkBy", {field: "id", values: ids});
                }
            })
        });
    })
    $("table").framework().bootstrapTable({
        height: 400,
        url: "/group/getListByPage",
        pagination: false,
        columns: [{
            checkbox: true,
            align: 'center',
            valign: 'middle'
        }, {
            field: 'id',
            title: 'ID',
            align: 'center',
            valign: 'middle'
        }, {
            field: '',
            title: '序号',
            align: 'center',
            valign: 'middle',
            formatter: function (value, row, index) {
                return index + 1;
            }
        }, {
            field: 'groupName',
            title: '组名',
            align: 'center',
            valign: 'middle'
        }, {
            field: 'createTime',
            title: '创建时间',
            align: 'center',
            valign: 'middle'
        }]
    });

    function refresh() {
        $('table').bootstrapTable('refresh');
    }

    function save() {
        var request = [];
        var selected = $('table').bootstrapTable('getSelections');
        for (i in selected) {
            request.push({versionInfoId: [[${id}]], groupInfoId: selected[i].id});
        }
        $.ajax({
            method: "post",
            url: createUrl("/versionGroup/save/[[${id}]]"),
            data: JSON.stringify(request),
            contentType: "application/json",
            success: function (result) {
                if (result.errorCode == 0) {
                    framework.successMsg("保存成功");
                } else {
                    framework.errorMsg("保存失败")
                }
            }
        })
    }
</script>
</html>
